package com.example.util;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;

/**
 * hibernate链接数据库工厂类
 */
public class Hibernateutil {
	
	private static SessionFactory sessionfc;
	private static Configuration config;

	/**
	 * 初始化hibernate链接
	 */
	static{
		config=new Configuration().configure();
		sessionfc=config.buildSessionFactory();
	}

	/**
	 * 打开数据库链接
	 * @return
	 */
	public static Session opensession(){
		return sessionfc.openSession();
	}
	
	public static Configuration getconfiguration(){
		return config;
	}

	/**
	 * 关闭数据库链接
	 * @param session
	 */
	public static void closesession(Session session){
		if(session!=null){
			session.close();
		}
	}
	
	
	

}
